<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>就业指导</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/css/scroll-bar.css">
    <link rel="stylesheet" href="/css/sub-page.css">
    <link rel="stylesheet" href="/lib/nprogress/nprogress.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>招生就业</cite></a>
                <a><cite>就业指导</cite></a>
            </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--工具栏-->
    <okToolbar>
        <button class="layui-btn" id="addUser">
            <i class="layui-icon">&#xe61f;</i>添加文章
        </button>
        <span>共有数据：<i id="countNum"></i> 条</span>
    </okToolbar>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="/lib/layui/layui.js"></script>
<script src="/lib/nprogress/nprogress.js"></script>
<script>
    // 进度条加载提示
    NProgress.start();
    window.onload = function () {
        NProgress.done();
    }
    // layui相关
    layui.use(['element', 'table', 'form', 'jquery', 'laydate', 'util'], function () {
        let element = layui.element;
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        // let util = layui.util;

        //渲染数据表格
        table.render({
            elem: '#tableId',
            url: '/manage/articles?code=guide',
            limit: 10,
            page: true,
            even: true,
            cols: [[
                {field: 'articleId', title: 'ID', width: 80, sort: true},
                {field: 'articleTitle', title: '文章标题',minWidth:200},
                {
                    field: 'publishDate',
                    title: '发布日期',
                    width: 120,
                    templet: "<div>{{layui.util.toDateString(d.publishDate, 'yyyy-MM-dd')}}</div>"
                },
                {field: 'sort', title: '排序', width: 90, edit: 'text'},
                {title: '操作', fixed: 'right', Width: 120, templet: '#operationTpl', align: 'center'}
            ]],
            done: function (res, curr, count) {
                $("#countNum").text(count);
            }
        });
        //表格工具列
        table.on('tool(tableFilter)', function (obj) {
            // var data = obj.data;
            let layEvent = obj.event;
            if (layEvent === 'edit') {
                var editLayer = layer.open({
                    title: '编辑文章',
                    type: 2,
                    maxmin: true,
                    shade: 0.5,
                    area: ['100%', '100%'],
                    content: '/manage/recruit/guide-edit.html?id='+ obj.data.articleId,
                    zIndex: layer.zIndex,
                    ready: function () {
                        //最大化页面层
                        layer.full();
                    },
                    end: function () {
                        $(".layui-laypage-btn")[0].click();
                    }
                });
            } else if (layEvent === 'del') {
                layer.confirm("确定要删除吗？", {skin: 'layui-layer-lan', icon: 2, title: '提示', anim: 6}, function () {
                    $.ajax({
                        url: '/manage/articles/' + obj.data.articleId,
                        type: 'DELETE',
                        dataType: 'json',
                        success: function (resp) {
                            if (resp) {
                                layer.msg("操作成功！", {icon: 1, time: 1000});
                                $(".layui-laypage-btn")[0].click();
                            }
                        }
                    })
                });
            }
        });
        //添加文章
        $("#addUser").click(function () {
            var addLayer = layer.open({
                title: '添加文章',
                type: 2,
                maxmin: true,
                shade: 0.5,
                anim: 4,
                area: ['100%', '100%'],
                content: '/manage/recruit/guide-add.html',
                zIndex: layer.zIndex,
                ready: function () {
                    layer.full();
                },
                end: function () {
                    $(".layui-laypage-btn")[0].click();
                }
            });
        });
        //修改排序
        table.on('edit(tableFilter)', function (obj) {
            let data = {articleId: obj.data.articleId, sort: obj.value};
            $.ajax({
                url: '/manage/articles',
                data: JSON.stringify(data),
                contentType: 'application/json',
                type: 'PUT',
                dataType: 'json',
                success: function (resp) {
                    if (resp.code===200) {
                        layer.msg("操作成功！", {icon: 6, time: 1000, anim: 4});
                    } else {
                        layer.msg("操作失败！", {icon: 5, time: 1000, anim: 4});
                    }
                }
            });

        });
        //监听置顶、推荐、头图推荐操作
        form.on('switch', function (obj) {
            let data = '{"articleId":' + this.value + ',\"' + this.name + '\":' + obj.elem.checked + '}';
            $.ajax({
                url: '/manage/articles',
                data: data,
                dataType: 'json',
                contentType: 'application/json',
                type: 'PUT',
                success: function (resp) {
                    if (resp) {
                        layer.tips('操作成功', obj.othis);
                    } else {
                        layer.tips(resp.msg, obj.othis);
                    }
                }
            });
        });
    });
</script>
<!--模板-->
<script type="text/html" id="coverTpl">
    <img src="{{d.articleCover}}"/>
</script>
<script type="text/html" id="bannerTpl">
    <input type="checkbox" name="banner" value="{{d.articleId}}" lay-skin="switch" lay-text="是|否" {{ d.banner== true ? 'checked' : ''}}>
</script>
<script type="text/html" id="indexTpl">
    <input type="checkbox" name="banner" value="{{d.articleId}}" lay-skin="switch" lay-text="是|否" {{ d.index== true ? 'checked' : ''}}>
</script>
<!--<script type="text/html" id="topTpl">-->
<!--<input type="checkbox" name="top" value="{{d.articleId}}" lay-skin="switch" lay-text="是|否" {{ d.top== true ? 'checked' : ''}}>-->
<!--</script>-->
<script type="text/html" id="recommendTpl">
    <input type="checkbox" name="recommend" value="{{d.articleId}}" lay-skin="switch" lay-text="是|否" {{ d.recommend== true ? 'checked' : ''}}>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:" title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    <a href="javascript:" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a></script>
</body>
</html>